$(function(){
	var orderStatus = $(".orderStatus").val() || -1;

	$('.datepicker').datepicker({
	     format: "yyyy-mm-dd",
	     language: "zh-CN",
	     orientation: "top left",
	     autoclose:true
	});

	var dataTable = $('#reviewList').dataTable({
		"ColumnDefs" : [ {
	        sDefaultContent : '',
	        aTargets : [ '_all' ]
		} ],
		bFilter: false,
		"bPaginate": false,
        aaData: [],
        aoColumns: [
            {mDataProp:"returnOrder"},
            {mDataProp:"checkedState"},
            {mDataProp:"finaceCheckedState"},
            {mDataProp:"purchaseType"},
            {mDataProp:"supplierCode"},
            {mDataProp:"supplierName"},
            {mDataProp:"settmentType"},
            {mDataProp:"returnDate"},
            {mDataProp:"returnPerson"},
            {mDataProp:"returnNumber"},
            {mDataProp:"returnAmount"},
            {mDataProp:"actualDeliveryNumber"},
            {mDataProp:"checkedState"},
        ],
        columnDefs:[
        {
        	targets:[12],
        	data:"checkedState",
        	render: function(data, type, full) {
                return "<a href='#'>查看</a> <a href='#'>编辑</a><a href='#'>批准</a><a href='#'>否决</a>";
            }
        }]
    } );
	$(".tabsItem").click(function(){
		orderStatus = $(this).val();
		$(".tabsItem").removeClass("active");
		$(this).addClass("active");
		refresh();
	});
	
	$(".searchBtn").click(function(){
		refresh();
	});
	
	function refresh(){
		var returnOrder = $(".returnOrder").val();
		var supplierCode = $(".supplierCode").val();
		var supplierName = $(".supplierName").val();
		var purchaseType = $(".purchaseType").val();
		var returnPerson = $(".returnPerson").val();
		var startReturnTime = $(".startReturnTime").val();
		var endReturnTime = $(".endReturnTime").val();
		RefreshTable('#reviewList', "/purchaseReturnOrder/finaceCheckList?orderStatus="+orderStatus+"&returnOrder="+returnOrder+"&supplierCode="+supplierCode
				+"&supplierName="+supplierName+"&purchaseType="+purchaseType+"&returnPerson="+returnPerson+"&startReturnTime="+startReturnTime+"&endReturnTime="+endReturnTime);
	}
	function RefreshTable(tableId, urlData)
    {
      //Retrieve the new data with $.getJSON. You could use it ajax too
      $.getJSON(urlData, null, function( json )
      {
        table = $(tableId).dataTable();
        oSettings = table.fnSettings();

        table.fnClearTable(this);

        for (var i=0; i<json.result.entityList; i++)
        {
          table.oApi._fnAddData(oSettings, json.data[i]);
        }

        oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
        table.fnDraw();
      });
    }
});